package hsrt.com.dynamiccomponent_android;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.lang.ref.WeakReference;

import hsrt.com.dynamiccomponent_android.dynamic_component.DataElementInterface;
import hsrt.com.dynamiccomponent_android.dynamic_component.DynamicComponentInterface;
import hsrt.com.dynamiccomponent_android.dynamic_component.DynamicDisplayManager;


public class Component1 implements DynamicComponentInterface {
    private WeakReference<DynamicDisplayManager> managerWeakReference;

    @Override
    public void setDynamicManager(DynamicDisplayManager manager) {
        managerWeakReference = new WeakReference<>(manager);
    }

    @Override
    public Integer registerName() {
        return R.layout.layout1;
    }


    @Override
    public void process(BaseViewHolder holder, MultiItemEntity item, BaseQuickAdapter adapter, boolean flagModify) {
        //todo 强转成dataelement类型, 这样就可以获取到数据.

        DynamicDisplayManager manager = managerWeakReference.get();
        if (manager != null) {
            holder.getView(R.id.button).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    DataElement1 dataElement1 = new DataElement1();
                    DataElement2 dataElement2 = new DataElement2();
                    dataElement1.setChildObjectFlag("aa");
                    dataElement2.setChildObjectFlag("aa");

                    dataElement1.setNext(dataElement2);
                    dataElement2.setPrevious(new WeakReference<>(dataElement1));

                    manager.batchC(dataElement1, 1);

                }
            });

            holder.getView(R.id.button2).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    DataElementInterface xx = (DataElementInterface) item;
                    manager.batchD(xx.getNext(),1);
                }
            });
        }

    }
}
